import type { Router } from 'vue-router'

export const setupRouterGuard = (router: Router) => {
  router.beforeEach(async (to) => {
    if (to.fullPath === _ViewPath.Login) return
    if (!getUserId()) return { path: _ViewPath.Login }
    if (getUserId() && !useAppStore().inited) {
      await useAppStore().Init()
      return to.fullPath
    }
  })
}
